// 撤销、恢复操作
class Stack {
  
  private recordList: string[]

  private pointer: number

  constructor() {
    // 操作记录
    this.recordList = []
    // 指针
    this.pointer = -1
  }

  getPointer() {
    return this.pointer
  }

  getRecordList() {
    return this.recordList
  }

  // 压栈
  push(item: string) {
    this.recordList.splice(++this.pointer, this.recordList.length, item)
  }

  // 弹栈
  undo() {
    if(this.pointer > 0) {
      this.pointer--
      return this.recordList[this.pointer]
    }
  }

  // 恢复
  redo() {
    if(this.pointer < this.recordList.length - 1) {
      this.pointer++
      return this.recordList[this.pointer]
    }
  }

  // 清空
  clear() {
    this.recordList = []
    this.pointer = -1
  }
}

export default Stack